<div class="layui-form" lay-filter="layuiadmin-form-dblink" style="padding: 20px 0 0 0;">
  <script type="text/html" template>
    <input type="hidden" name="id" value="{{ d.params.id || '' }}"  class="layui-input">
  </script>
  <div class="layui-form-item">
    <label class="layui-form-label">连接地址</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="hostname" value="{{ d.params.hostname || '' }}" lay-verify="required|hostname" placeholder="请输入连接地址(推荐使用FQDN)" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">连接端口</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="port" value="{{ d.params.port || '' }}" lay-verify="number" placeholder="请输入端口(默认:6030)" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">数据库登录账号</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="username" value="{{ d.params.username || '' }}"  lay-verify="required" placeholder="请输入用户名(默认:root)" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">数据库密码</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="password" value="{{ d.params.password || '' }}" lay-verify="required" placeholder="请输入密码(默认:taosdata)" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-dblink-front-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form', 'upload'], function(){
  var $ = layui.$
  ,form = layui.form
  ,upload = layui.upload
  ,admin = layui.admin;

  form.verify({
    hostname: function (value, item) { //value：表单的值、item：表单的DOM对象
      if (value !== '') {
        //执行 Ajax 后重载
        let r = false;
        admin.req({
          type: 'get',
          url: 'dataSource/hostname',
          traditional: true,
          async:false,//同步
          data:{"hostname":value},
          success: function (data) {
            r = data.data;
          }
        })
        if (r){
          return ;
        }else {
        return "hostname 重复,禁止重复添加";
        }
      }
    }
  });

})
</script>